//
//  TRHTTPTool.m
//  UnaMicroBlog
//
//  Created by lanou3g on 15/10/20.
//  Copyright (c) 2015年 tanrong. All rights reserved.
//

#import "TRHTTPTool.h"
#import "AFNetworking.h"

@implementation TRHTTPTool
+(void)get:(NSString*)url params:(NSDictionary*)params success:(void (^)(id responseObj))success failure:(void (^)(NSError * error))failure
{
    //1、获得请求管理者
    AFHTTPRequestOperationManager * mgr = [AFHTTPRequestOperationManager manager];

    //3、发送GET请求
    [mgr GET:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObj) {
        if (success) {
            success(responseObj);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];

}

+ (void)post:(NSString *)url params:(NSDictionary *)params success:(void (^)(id))success failure:(void (^)(NSError *))failure
{
    // 1.获得请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    
    // 2.发送POST请求
    [mgr POST:url parameters:params
      success:^(AFHTTPRequestOperation *operation, id responseObj) {
          if (success) {
              success(responseObj);
          }
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          if (failure) {
              failure(error);
          }
      }];
}


@end
